package com.hui.servlet.student;

import com.hui.entity.Student;
import com.hui.service.StudentService;
import com.hui.util.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/07/09/11:03
 * @Description:  班级号查询学生
 */
@WebServlet(name = "selectStudentByClassIdServlet", urlPatterns = "/selectStudentByClassId")
public class SelectStudentByClassIdServlet extends HttpServlet {
    private StudentService studentService = ServiceFactory.getStudentService();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String classId =req.getParameter("classId");
        List<Student> studentList = studentService.getStudentByClassId(Integer.parseInt(classId));
        // 将结果保存到session中，并重定向 home.jsp
        HttpSession session = req.getSession();
        session.setAttribute("studentList",studentList);
        session.setAttribute("totalPage",1);
        resp.sendRedirect("home.jsp");

    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

}
